import { _decorator, Component, view } from "cc";
import { SetBasicInfo } from "../Utils/SetBasicInfo";
const { ccclass, property } = _decorator;

@ccclass("Bullet")
export class Bullet extends Component {
  pageWidth: number = 0;
  pageHeight: number = 0;

  @property
  speed: number = 200;

  start() {
    this.getBgHeight();
  }

  update(deltaTime: number) {
    const position = this.node.position;
    SetBasicInfo.setPosition(this.node, {
      y: position.y + this.speed * deltaTime,
    });

    if (position.y > this.pageHeight) {
      this.node.destroy();
    }
  }

  getBgHeight() {
    const { width, height } = view.getVisibleSize();
    this.pageWidth = width;
    this.pageHeight = height;
  }
}
